<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>码表管理--${fns:getConfig('productName')}</title>
<link href="${ctx}/static/bootstrap/2.3.1/css/docs.css" type="text/css" rel="stylesheet" />
<style type="text/css">
 /*tetxarea 样式*/
        .wordCount{ position:relative;width: 600px; }
        .wordCount textarea{ width: 100%; height: 100px;}
        .wordCount .wordwrap{ position:absolute; right: 6px; bottom: 6px;}
        .wordCount .word{ color: red; padding: 0 4px;;}
        .wyInline{display:inline-block;}
textarea{
width:50%;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
	$("#type").focus();
	$("#inputForm").validate({
		rules: {
			category:{
				required:true,
				number:true,
				maxlength:9,
				min:0
			},
			codeId:{
				required:true,
// 				number:true,
				maxlength:9,
// 				min:0,
				//remote:"${ctx}/code/checkId.do?a=${entity.category}&b="+$('#category').val()
				remote: {
                    url: "${ctx}/code/checkId.do",
                    type: "Post",
                    data: {
                    	category: function () { return $("#category").val(); },
                    	codeId:function(){return $("#codeId").val();},
                    	oldcategory: function () { return "${entity.category}"; },
                    	oldcodeId: function () { return "${entity.codeId}"; },
                    }
				}
			},
			codeName:{
				required:true
			}
		},
		messages: {
			codeId: {remote: "该编号已存在,换一个编号试试~"},
		},
		submitHandler:function(form){
			loading("保存中...");
			form.submit();
		},
		errorContainer: "#messageBox",
		errorPlacement: function(error, element) {
			$("#messageBox").text("输入有误，请先更正。");
			if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
				error.appendTo(element.parent().parent());
			} else {
				error.insertAfter(element);
			}
		}
	});
});

</script>
</head>
<body>
<ul class="nav nav-tabs" style="margin:0 4px;">
		<li>
			<a href="${ctx}/code/show.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}">
				<i class="icon icon-edit"></i>&nbsp;Code列表
			</a>
		</li>
		<li class="active">
			<a href="${ctx}/code/input.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}"> 
				<i class="icon icon-list"></i>&nbsp;${not empty
				entity.id?'修改':'新增'}
			</a>
		</li>
	</ul>
	<form id="inputForm" action="${ctx}/code/save.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}"
		method="post"  class="form-horizontal m"  enctype="multipart/form-data">
 		<input type="hidden" name="token" value="${token}">
		<input type="hidden" name="id" value="${entity.id}" />
		<tags:message content="${msg}" />
		<fieldset>
    			<legend>Code信息</legend>
				<div class="control-group">
					<label class=" control-label">类型<font style="color:red;">*</font>:</label>
					<div class="controls">
					  <input class=" required" id="category" name="category"
							type="text" value="${entity.category}">
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">编码<font style="color:red;">*</font>:</label>
					<div class="controls">
					  <input class=" required" id="codeId" name="codeId"
							type="text" value="${entity.codeId}">
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">名称<font style="color:red;">*</font>:</label>
					<div class="controls">
					  <input  id="codeName" name="codeName"
							type="text" value="${entity.codeName}">
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">表述:</label>
					<div class="controls">
					  <input  id="categoryDesc" name="categoryDesc"
							type="text" value="${entity.categoryDesc}">
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">描述:</label>
					<div class="controls">
					  <input  id="description" name="description"
							type="text" value="${entity.description}">
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">是否启用:</label>
					<div class="controls">
					 <pt:code category="1000" name="useFlag" hasEmpty="false"  default="${entity.useFlag}" width="220"></pt:code>
					</div>
				</div>
				<div class="control-group">
					<label class=" control-label">备注:</label>
					<div class="controls">
						<input class="" id="remark" name="remark"
							type="text" value="${entity.remark}">
					</div>
				</div>
		</fieldset>
      <div class="form-actions" style="text-align:center;padding-left:0px;">
				<input id="btnSubmit" class="btn btn-primary" type="submit"
					value="保 存" />
					&nbsp; 
<input id="btnCancel" class="btn" type="button" value="返 回" onclick="JavaScript:history.go(-1);" />
	 </div>
	</form>
<script>

    $(function(){

        //先选出 textarea 和 统计字数 dom 节点

        var wordCount = $("#wordCount"),

            textArea = wordCount.find("textarea"),

            word = wordCount.find(".word");

        //调用

        statInputNum(textArea,word);



    });

    /*

    * 剩余字数统计

    * 注意 最大字数只需要在放数字的节点哪里直接写好即可 如：<var class="word">200</var>

    */

    function statInputNum(textArea,numItem) {

        var max = numItem.text(),

            curLength=null;

        if(textArea[0])textArea[0].setAttribute("maxlength", max);

        if(textArea.val())curLength = textArea.val().length;

        numItem.text(max - curLength);

        textArea.on('input propertychange', function () {

            numItem.text(max - $(this).val().length);

        });

    }

</script>
</body>
</html>
